/**
 * 
 */
package com.yidu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.domain.Role;
import com.yidu.domain.vo.RoleVo;
import com.yidu.service.RoleService;
import com.yidu.utils.Pages;
import com.yidu.utils.State;
import com.yidu.utils.Tools;

/**
 * @描述 角色控制器层
 * @author 梁海长
 * @date 2019年9月26日上午9:57:47
 *
 */
@Controller
@RequestMapping("Role")
public class RoleController {
	@Resource
	private RoleService roleService ;
	/**
	 * 查询全部信息，不分页
	 * @return
	 */
	@RequestMapping("findAll")
	@ResponseBody
	public List<RoleVo> findAll(RoleVo roleVo){
		List<RoleVo> list = roleService.findAll(roleVo);
		return list;
	}
	
	@RequestMapping("updateRolevalidity")
	@ResponseBody
	public State updateRolevalidity(String roleId,String roleValidity) {
		roleService.updateRolevalidity(roleId, roleValidity);
		State bm=new State();
		bm.setState(1);
		return bm;
	}
	/**
	 * 查询全部信息，分页
	 * @param roleVo
	 * @param pages
	 * @param page
	 * @return
	 */
	@RequestMapping("findAllPage")
	@ResponseBody
	public Map<String, Object> findAllPage(RoleVo roleVo , Pages pages , String page){
		pages.setCurPage(Integer.valueOf(page));
		List<RoleVo> list = roleService.findAllPage(roleVo,pages);
		pages.setTotalRows(roleService.count(roleVo).intValue());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("count", pages.getTotalRows());
		map.put("data", list);
		return map;
	}
	/**
	 * @param rolevo
	 * @return
	 */
	@RequestMapping("RoleInsert")
	@ResponseBody
	public State RoleInsert(RoleVo rolevo) {
		State bm=new State();
		rolevo.setRoleTime(Tools.getCurDateTime());
		if(rolevo.getRoleId()!=null && !"".equals(rolevo.getRoleId())) {
			roleService.update(rolevo);
		}else {
			roleService.add(rolevo);
		}
		bm.setState(1);
		bm.setMsg("操作成功");
		return bm;
	}
	@RequestMapping("RoleById")
	@ResponseBody
	public RoleVo RoleById(String id) {
		RoleVo rl=roleService.findById(id);
		return rl;
	}
}
